package com.other.generater;

import java.util.Objects;

/**
 * Created by baiguantao on 2017/12/6.
 * 用于实体生成
 * 写入文件
 *
 */
public class BeanUtils {

    /**
     * 分隔符以外的所有都大写
     * 比如是cg_repay
     * num=0 的话是cgRepay
     * <0 则是CgRepay
     * @param type
     */
    public static String setModelName(String name,String spilt,Integer num) {
        StringBuffer sb=new StringBuffer();
        if (Objects.isNull(spilt)) {
            spilt="_";
        }
        if (Objects.isNull(num)) {
            num=0;
        }
        String[] strs=name.split(spilt);
        if (strs.length>1) {
            for (int i=0;i<strs.length;i++) {
                String s=strs[i];
                if (i>num) {
                    sb.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
                }else{
                    sb.append(s);
                }
            }
        }else{
            sb.append(name);
        }

        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(setModelName("cg_repay",null,-1));
    }
}
